package cn.zjutleo.village_server.controller;

import cn.zjutleo.village_server.annotation.RequiresLogin;
import cn.zjutleo.village_server.dto.AccurateSupportApplyDto;
import cn.zjutleo.village_server.dto.AccurateSupportSurveyDto;
import cn.zjutleo.village_server.service.AccurateSupportService;
import cn.zjutleo.village_server.util.ThreadLocalUtil;
import cn.zjutleo.village_server.vo.AccurateSupportApplyDetailVo;
import cn.zjutleo.village_server.vo.AccurateSupportApplyRoughVo;
import cn.zjutleo.village_server.vo.ResponseBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : Qin Zhenghan
 * @date : Created in 2021/10/2
 * @description: 精准帮扶相关控制类
 */
@Api(tags = "精准帮扶相关控制类")
@RestController
@RequestMapping("/accurateSupport")
public class AccurateSupportController {

    @Resource
    private AccurateSupportService accurateSupportService;

    @ApiOperation("村民精准帮扶申报")
    @RequiresLogin
    @PostMapping("/apply")
    public ResponseBean<Object> applyForAccurateSupport(@RequestBody @Validated AccurateSupportApplyDto accurateSupportApplyDto) {
        Integer userId = ThreadLocalUtil.getCurrentUser();
        accurateSupportService.applyForAccurateSupport(accurateSupportApplyDto, userId);
        return new ResponseBean<>(null);
    }

    @ApiOperation("获取精准帮扶粗略信息列表")
    @GetMapping("/apply/list")
    public ResponseBean<List<AccurateSupportApplyRoughVo>> getAccurateSupportApplyRoughVos() {
        List<AccurateSupportApplyRoughVo> list = accurateSupportService.getAccurateSupportApplyRoughVos();
        return new ResponseBean<>(list);
    }

    @ApiOperation("根据申请表id获取精准帮扶申请详细信息")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "applyId", value = "精准帮扶申请表id", paramType = "path", dataType = "Integer")
    )
    @GetMapping("/apply/{applyId}")
    public ResponseBean<AccurateSupportApplyDetailVo> getAccurateSupportApplyDetailVo(@PathVariable Integer applyId) {
        AccurateSupportApplyDetailVo accurateSupportApplyDetailVo = accurateSupportService.getAccurateSupportApplyDetailVo(applyId);
        return new ResponseBean<>(accurateSupportApplyDetailVo);
    }

    @ApiOperation("上传精准帮扶走访报告")
    @PostMapping("/survey/add")
    public ResponseBean<Object> addAccurateSupportSurvey(@RequestBody AccurateSupportSurveyDto accurateSupportSurveyDto) {
        accurateSupportService.addAccurateSupportSurvey(accurateSupportSurveyDto);
        return new ResponseBean<>(null);
    }
}
